//package com.linQing.waterWork.config;
//
//import com.linQing.waterWork.utils.DateUtils;
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.mybatis.spring.SqlSessionFactoryBean;
//import org.mybatis.spring.SqlSessionTemplate;
//import org.mybatis.spring.annotation.MapperScan;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//import org.springframework.jdbc.datasource.DriverManagerDataSource;
//
//import javax.sql.DataSource;
//import java.time.Year;
//
///**
// * @program:
// * @description: 数据库配置2
// **/
//@Configuration
//@MapperScan(basePackages = "com.linQing.waterWork.mapper.last",sqlSessionFactoryRef = "SqlLastSqlSessionFactory")
//public class SqlLastConfig {
//
//    @Value("${spring.data.datasource.last.driver-class-name}")
//    String driverClass;
//    @Value("${spring.data.datasource.last.url}")
//    String url;
//    @Value("${spring.data.datasource.last.username}")
//    String userName;
//    @Value("${spring.data.datasource.last.password}")
//    String passWord;
//
//    @Bean(name = "sqlLastDataSource")
//    @ConfigurationProperties("spring.datasource.last")
//    public DataSource masterDataSource(){
//        DriverManagerDataSource dataSource = new DriverManagerDataSource();
//        dataSource.setDriverClassName(driverClass);
//        dataSource.setUrl(url+(Year.now().getValue() - 1)+';');
//        dataSource.setUsername(userName);
//        dataSource.setPassword(passWord);
//        return dataSource;
//    }
//
//    @Bean(name = "sqlLastSqlSessionFactory")
//    public SqlSessionFactory sqlSessionFactory(@Qualifier("sqlLastDataSource") DataSource dataSource) throws Exception {
//        SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
//        sessionFactoryBean.setDataSource(dataSource);
//        sessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver()
//                .getResources("classpath*:mapper/last/*.xml"));
//
//        return sessionFactoryBean.getObject();
//    }
//
//    @Bean(name = "sqlLastSqlSessionTemplate")
//    public SqlSessionTemplate sqlSessionFactoryTemplate(@Qualifier("sqlLastSqlSessionFactory")SqlSessionFactory sqlSessionFactory ) throws Exception {
//        return new SqlSessionTemplate(sqlSessionFactory);
//    }
//}
//
